import { observer } from "./index"

let oldArrayProtoMethods = Array.prototype
export let ArrMethods = Object.create(oldArrayProtoMethods)
console.log("arrMethods",ArrMethods)
let methods = [
  "push",
  "pop",
  "shift",
  "unshift",
  "splice"
]
const arrAddMethods = ["push","unshift"]
methods.forEach(item =>{
  ArrMethods[item] = function(...args){
    console.log("arguments",args[0])
    console.log("数组劫持")
    let inserted
    switch(item){
      case "push":
      case "unshift":
        inserted = args
        break;
      case "splice":
        inserted = args.splice(2)
    }
    let ob = this.__ob__
    ob.observerArray(inserted)
    const result = oldArrayProtoMethods[item].apply(this,args)
  }
})